clear
close all
clc
delete *.asv

cd ..\
cd Stored_File

load Policy_3state.mat

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% Figure 2: Sample path consumption %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

w_thr = max(wgrid(((P_new(1)-P_new<10^(-10)))));

path=[3,3,3,2,2,2,1,3,1,3,3,3,3,2,1];
tt=[1:1:length(path)];

for i=1:length(path)    
    if path(i)==1
eyt(i)=ey1;
eot(i)=1-ey1;
    elseif path(i)==2
eyt(i)=ey2;
eot(i)=1-ey2;
    elseif path(i)==3
eyt(i)=ey3;
eot(i)=1-ey3;
    end
end

for i=1:length(path)-1
wt(1)=w1(1);    
    if path(i)==1
wt(i+1)=interp1(wgrid,w1,wt(i),'spline');
    elseif path(i)==2
wt(i+1)=interp1(wgrid,w2,wt(i),'spline');
    elseif path(i)==3
wt(i+1)=interp1(wgrid,w3,wt(i),'spline');
    end
end

for i=1:length(path)      
    if path(i)==1
cot(i)=(1-interp1(wgrid,cy1,wt(i),'spline'));
    elseif path(i)==2
cot(i)=(1-interp1(wgrid,cy2,wt(i),'spline'));
    elseif path(i)==3
cot(i)=(1-interp1(wgrid,cy3,wt(i),'spline'));
    end  
end

for i=1:length(path)      
    if path(i)==1
cyt(i)=(interp1(wgrid,cy1,wt(i),'spline'));
    elseif path(i)==2
cyt(i)=(interp1(wgrid,cy2,wt(i),'spline'));
    elseif path(i)==3
cyt(i)=(interp1(wgrid,cy3,wt(i),'spline'));
    end  
end

cy0=interp1(wgrid,cy1,w_thr,'spline');

figure('name','Figure 2: Sample Path of Young Consumption Share')
scatter([1:1:length(path)+1],[cy0 cyt],'b'); hold on
plot([1:1:length(path)+1],[cy0 cyt],'b--'); hold on
plot([1:1:length(path)+1],0.5.*ones(1,length(tt)+1),':')
